home *** CD-ROM | disk | FTP | other *** search
- n = 10;
- riseNow = false;
- fallNow = false;
- Stage.scaleMode = "noScale";
- this.onEnterFrame = function()
- {
- i = 1;
- while(i < n)
- {
- j = 1;
- while(j < n)
- {
- if(i != j && _root["ball" + i].inside != false && _root["ball" + j].inside != false)
- {
- distx = _root["ball" + j]._x - _root["ball" + i]._x;
- disty = _root["ball" + j]._y - _root["ball" + i]._y;
- dist = Math.sqrt(distx * distx + disty * disty);
- if(dist <= 30)
- {
- theta = Math.atan2(disty,distx);
- nx = Math.cos(theta);
- ny = Math.sin(theta);
- x = _root["ball" + i].dx - _root["ball" + j].dx;
- y = _root["ball" + i].dy - _root["ball" + j].dy;
- ndot = x * nx + y * ny;
- ix = nx * ndot;
- iy = ny * ndot;
- distx2 = - _root["ball" + j]._x + _root["ball" + i]._x;
- disty2 = - _root["ball" + j]._y + _root["ball" + i]._y;
- dist2 = distx * distx + disty * disty;
- theta2 = Math.atan2(disty2,distx2);
- nx2 = Math.cos(theta2);
- ny2 = Math.sin(theta2);
- x2 = - _root["ball" + i].dx + _root["ball" + j].dx;
- y2 = - _root["ball" + i].dy + _root["ball" + j].dy;
- ndot2 = x2 * nx2 + y2 * ny2;
- ix2 = nx2 * ndot2;
- iy2 = ny2 * ndot2;
- _root["ball" + i].dx -= ix;
- _root["ball" + i].dy -= iy;
- _root["ball" + i]._x += _root["ball" + i].dx;
- _root["ball" + i]._y += _root["ball" + i].dy;
- movex = Math.cos(theta) * (30 - dist) / 2;
- movey = Math.sin(theta) * (30 - dist) / 2;
- _root["ball" + i]._x -= movex;
- _root["ball" + i]._y -= movey;
- _root["ball" + j]._x += movex;
- _root["ball" + j]._y += movey;
- _root["ball" + j].dx -= ix2;
- _root["ball" + j].dy -= iy2;
- _root["ball" + j]._x += _root["ball" + j].dx;
- _root["ball" + j]._y += _root["ball" + j].dy;
- }
- }
- j++;
- }
- i++;
- }
- };
-